package com.qf.service.Impl;


import com.qf.dao.HealthDao;
import com.qf.dao.Impl.HealthDaoImpl;
import com.qf.entity.Health;
import com.qf.service.HealthService;
import com.qf.util.DruidUtil;
import com.qf.util.Page;

import java.util.List;

public class HealthServiceImpl implements HealthService {
    private HealthDao healthDao = new HealthDaoImpl();

    @Override
    public List<Health> showAllHealth(Page page) {
        List<Health> healthList = null;
        healthList = healthDao.selectAllHealth(page);
        long totalcount = healthDao.selectCountHealth();
        page.setTotalCount(totalcount);
        DruidUtil.close();
        return healthList;
    }

    @Override
    public Health showByHealth(Integer id) {
        Health health = null;
        health = healthDao.selectByHealth(id);
        DruidUtil.close();
        return health;
    }

    @Override
    public int add(Health health) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = healthDao.insert(health);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public int update(Health health) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = healthDao.update(health);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Integer delete(Integer id) {
        int result = 0;
        try {
            DruidUtil.begin();
            result = healthDao.delete(id);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }
}
